import type { FormList, SearchList } from "@/types/form";
import type { TableColumn, TableOptions } from "@/types/public";
import { MENU_MODULE } from "@/utils/constants";
import { FORM_REQUIRED } from "@/utils/config";

// 搜索数据
export const searchList = (): SearchList[] => [
    {
        label: "用户名",
        name: "username",
        component: "Input",
    },
    {
        label: "姓名",
        name: "title",
        component: "Input",
    },
    {
        label: "角色",
        name: "module",
        wrapperWidth: 170,
        component: "Select",
        componentProps: {
            options: MENU_MODULE(),
        },
    },
];

/**
 * 表格数据
 * @param optionRender - 渲染操作函数
 */
export const tableColumns = (optionRender: TableOptions<object>): TableColumn[] => {
    return [
        {
            title: "ID",
            dataIndex: "id",
            width: 100,
        },
        {
            title: "用户名",
            dataIndex: "username",
            width: 150,
        },
        {
            title: "密码",
            dataIndex: "title",
            width: 400,
        },
        {
            title: "角色",
            dataIndex: "content",
            width: 120,
        },
        {
            title: "电话",
            dataIndex: "content",
            width: 120,
        },
        {
            title: "添加日期",
            dataIndex: "content",
            width: 120,
        },
        {
            title: "操作",
            dataIndex: "operate",
            width: 200,
            render: (value: unknown, record: object) => optionRender(value, record),
        },
    ];
};

// 新增数据
export const createList = (): FormList[] => [
    {
        label: "用户名",
        name: "username",
        rules: FORM_REQUIRED,
        component: "Input",
    },
    {
        label: "密码",
        name: "password",
        rules: FORM_REQUIRED,
        component: "Input",
    },
    {
        label: "姓名",
        name: "name",
        rules: FORM_REQUIRED,
        component: "Input",
    },
    {
        label: "电话",
        name: "phone",
        rules: FORM_REQUIRED,
        component: "Input",
    },
    {
        label: "角色",
        name: "real_name",
        rules: FORM_REQUIRED,
        component: "Select",
        componentProps: {
            options: MENU_MODULE(),
        },
    },
];
